﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

namespace lcmyjobs.Web.invite
{
    public partial class SList : BasePage
    {
        int type = 0, salary = 0, edu = 0, mtime = 0, exp = 0, lan = 0, level = 0, count = 0;
        string jobs, area, trade, mtimes, major, rtime;
        lcmyjobs.BLL.user_basic bub = new BLL.user_basic();
        lcmyjobs.BLL.news bn = new BLL.news();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Title = string.Format("搜索人才信息--猎头 猎头公司 聊城猎头 聊城猎头公司 {0}", Application["webname"].ToString(), Application["webregion"].ToString());
                int id = int.Parse(Application["webid"].ToString());
                Repeater1.DataSource = bn.GetListNews(id, 6, 5);
                Repeater1.DataBind();
                if (PreviousPage != null && PreviousPage.IsCrossPagePostBack &&
               PreviousPage.IsValid)
                {

                    if (((RadioButton)PreviousPage.FindControl("rbtnew")).Checked) type = 2;
                    if (((RadioButton)PreviousPage.FindControl("rbtold")).Checked) type = 1;
                    jobs = ((TextBox)PreviousPage.FindControl("txtjob")).Text.Trim();
                    area = ((TextBox)PreviousPage.FindControl("txtarea")).Text.Trim();
                    trade = ((TextBox)PreviousPage.FindControl("txttrade")).Text.Trim();
                    salary = int.Parse(((DropDownList)PreviousPage.FindControl("ddlsalarym")).SelectedValue.ToString());
                    edu = int.Parse(((DropDownList)PreviousPage.FindControl("ddledu")).SelectedValue.ToString());

                    if (((RadioButton)PreviousPage.FindControl("rbtt1")).Checked) mtime = 1;
                    if (((RadioButton)PreviousPage.FindControl("rbtt2")).Checked) mtime = 2;
                    if (((RadioButton)PreviousPage.FindControl("rbtt3")).Checked) { mtime = 3; mtimes = ((TextBox)PreviousPage.FindControl("txttime")).Text.ToString(); }
                    exp = int.Parse(((DropDownList)PreviousPage.FindControl("ddlExp")).SelectedValue.ToString());
                    major = ((TextBox)PreviousPage.FindControl("txtmajor")).Text.Trim();
                    lan = int.Parse(((System.Web.UI.HtmlControls.HtmlSelect)PreviousPage.FindControl("selange")).Value.ToString());
                    level = int.Parse(((System.Web.UI.HtmlControls.HtmlSelect)PreviousPage.FindControl("selevel")).Value.ToString());
                    string t = ((DropDownList)PreviousPage.FindControl("ddlrTime")).Text.Trim();
                    DateTime dt = DateTime.Now;
                    if (t == "不限") rtime = "";
                    if (t == "近三天") rtime = dt.AddDays(-3).ToString();
                    if (t == "近一周") rtime = dt.AddDays(-7).ToString();
                    if (t == "近半月") rtime = dt.AddDays(-15).ToString();
                    if (t == "近一月") rtime = dt.AddMonths(-1).ToString();
                    if (t == "近两月") rtime = dt.AddMonths(-2).ToString();
                    if (t == "近三月") rtime = dt.AddMonths(-3).ToString();
                    string keys = ((TextBox)PreviousPage.FindControl("txtKeyword")).Text.Trim();
                    lcmyjobs.Model.searchCondition sc = new Model.searchCondition();
                    //sc.type = type;
                    sc.jobs = jobs;
                    sc.area = area;
                    sc.trade = trade;
                    //sc.salary = salary;
                    //sc.edu = edu;
                    //sc.mtime = mtime;
                    //sc.mtimes = mtimes;
                    sc.exp = exp;
                    //sc.major = major;
                    //sc.lan = lan;
                    //sc.level = level;
                    //sc.rtime = rtime;
                    sc.keyword = keys;
                    Session["user_sc"] = sc;
                    getdate(1, AspNetPager1.PageSize, sc);
                }
                else
                {
                    Response.Redirect("searchResume.html");
                }
            }

        }
        protected void getdate(int start, int endindex, lcmyjobs.Model.searchCondition sc)
        {
            SqlParameter[] parameters = {			 
			 			 new SqlParameter("@job_name1", SqlDbType.NVarChar,20),     //0
                          new SqlParameter("@job_name2", SqlDbType.NVarChar,20),    //1
                          new SqlParameter("@job_name3", SqlDbType.NVarChar,20),    //2
                          new SqlParameter("@types", SqlDbType.Int,4),              //3
                          new SqlParameter("@lowpay", SqlDbType.Int,4),             //4
                          new SqlParameter("@highpay", SqlDbType.Int,4),            //5
                          new SqlParameter("@edu", SqlDbType.Int,4),                //6
                          new SqlParameter("@exp", SqlDbType.Int,4),                //7
                           new SqlParameter("@rtime", SqlDbType.DateTime),          //8
                         new SqlParameter("@areas1", SqlDbType.NVarChar,20),        //9
			 			 new SqlParameter("@areas2", SqlDbType.NVarChar,20),        //10
			 			 new SqlParameter("@areas3", SqlDbType.NVarChar,20),        //11
			 			 new SqlParameter("@trades1", SqlDbType.NVarChar,20),       //12
			 			 new SqlParameter("@trades2", SqlDbType.NVarChar,20),       //13
			 			 new SqlParameter("@trades3", SqlDbType.NVarChar,20),       //14
			 			 new SqlParameter("@major1", SqlDbType.NVarChar,20),        //15
			 			 new SqlParameter("@major2", SqlDbType.NVarChar,20),        //16
			 			 new SqlParameter("@major3", SqlDbType.NVarChar,20),        //17
			 			  new SqlParameter("@jobtime", SqlDbType.NVarChar,20),      //18
                           new SqlParameter("@jobtimes", SqlDbType.DateTime),       //19
                           new SqlParameter("@lan", SqlDbType.Int,4),               //20
			 			 new SqlParameter("@level", SqlDbType.Int,4),               //21
			 			 new SqlParameter("@startIndex", SqlDbType.Int,4),          //22
			 			 new SqlParameter("@endIndex", SqlDbType.Int,4),            //23
			 			new SqlParameter("@keyword",SqlDbType.NVarChar,20),         //24
			 			 new SqlParameter("@count", SqlDbType.Int,4)                //25
			 			    
			 			 };
            string[] a;
            if (sc.jobs != "")
            {
                a = sc.jobs.Split(',');
                if (a.Length > 0)
                    parameters[0].Value = a[0];
                if (a.Length > 1)
                    parameters[1].Value = a[1];
                if (a.Length > 2)
                    parameters[2].Value = a[2];
            }
            parameters[3].Value = type;
            int low = 0, hi = int.MaxValue;
            //if (sc.salary == 1) { hi = 10; }
            //if (sc.salary == 2) { low = 10; hi = 15; }
            //if (sc.salary == 3) { low = 15; hi = 20; }
            //if (sc.salary == 4) { low = 20; hi = 30; }
            //if (sc.salary == 5) { low = 30; hi = 50; }
            //if (sc.salary == 6) { low = 50; hi = 100; }
            //if (sc.salary == 7) { low = 100; }
            //parameters[4].Value = low;
            //parameters[5].Value = hi;
            //parameters[6].Value = sc.edu;
            //parameters[7].Value = sc.exp;
            //if (sc.rtime != "")
            //    parameters[8].Value = sc.rtime;
            //else
            //    parameters[8].Value = DateTime.Now.AddYears(-1);
            //if (sc.area != "")
            //{
            //    a = sc.area.Split(',');
            //    if (a.Length > 0)
            //        parameters[9].Value = a[0];
            //    if (a.Length > 1)
            //        parameters[10].Value = a[1];
            //    if (a.Length > 2)
            //        parameters[11].Value = a[2];
            //}
            //if (sc.trade != "")
            //{
            //    a = sc.trade.Split(',');
            //    if (a.Length > 0)
            //        parameters[12].Value = a[0];
            //    if (a.Length > 1)
            //        parameters[13].Value = a[1];
            //    if (a.Length > 2)
            //        parameters[14].Value = a[2];
            //}
            //if (sc.major != "")
            //{
            //    a = sc.major.Split(',');
            //    if (a.Length > 0)
            //        parameters[15].Value = a[0];
            //    if (a.Length > 1)
            //        parameters[16].Value = a[1];
            //    if (a.Length > 2)
            //        parameters[17].Value = a[2];
            //}
            //if (sc.mtime == 0)
            //    parameters[18].Value = "不限";
            //else if (sc.mtime == 1)
            //    parameters[18].Value = "随时";
            //else if (sc.mtime == 2)
            //    parameters[18].Value = "面谈";
            //else if (sc.mtime == 3)
            //{
            //    parameters[19].Value = sc.mtimes;
            //}
            //parameters[20].Value = sc.lan;
            //parameters[21].Value = sc.level;
            parameters[22].Value = start;
            parameters[23].Value = endindex;
            parameters[24].Value = sc.keyword;
            parameters[25].Direction = ParameterDirection.Output;
            DataSet ds = bub.PageUserSearch(parameters,1);
            AspNetPager1.RecordCount = int.Parse(parameters[25].Value.ToString());
            GridView1.DataSource = ds.Tables[0];
            GridView1.DataBind();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            if (Session["user_sc"] != null)
            {
                getdate(AspNetPager1.StartRecordIndex, AspNetPager1.EndRecordIndex, (lcmyjobs.Model.searchCondition)Session["user_sc"]);
            }

        }
    }
}